package service;

import java.util.ArrayList;
import java.util.List;

import modelo.AreaDao;
import modelo.CajaDao;

import beans.*;
import entities.*;

public class AreaSrv {

	private static AreaSrv instancia = null;
	
	public static AreaSrv getInstancia() {
		if( instancia == null) {
			instancia = new AreaSrv();
		}
		return instancia;
	}

	public AreaEntity bean2Entity(AreaBean area) {
		AreaEntity areaEntity = new AreaEntity();
		areaEntity.setId(area.getId());
		areaEntity.setTipo(area.getTipo());
		areaEntity.setDisponibilidad(area.getDisponibilidad());
		areaEntity.setDeposito(DepositoSrv.getInstancia().bean2Entity(area.getDeposito()));
//		List<ComandaEntity> comandasEntity = new ArrayList<ComandaEntity>();
//		for (ComandaBean comandaBean: area.getComanda()) {
//			ComandaEntity comandaEntity = ComandaSrv.getInstancia().bean2Entity(comandaBean);
//			comandasEntity.add(comandaEntity);
//		}
//		areaEntity.setComandas(comandasEntity);
		return areaEntity;
	}

	public AreaBean entity2Bean(AreaEntity area) {
		AreaBean areaBean = new AreaBean();
		areaBean.setId(area.getId());
		areaBean.setTipo(area.getTipo());
		areaBean.setDisponibilidad(area.getDisponibilidad());
		areaBean.setDeposito(DepositoSrv.getInstancia().entity2Bean(area.getDeposito()));
//		List<ComandaBean> comandasBean= new ArrayList<ComandaBean>();
//		for (ComandaEntity comandaEntity: area.getComandas()) {
//			ComandaBean comandaBean= ComandaSrv.getInstancia().entity2Bean(comandaEntity);
//			comandasBean.add(comandaBean);
//		}
//		areaBean.setComanda(comandasBean);
		return areaBean;
	}

	public void guardarArea(AreaBean area) {
		AreaEntity areaEntity = this.bean2Entity(area);
		AreaDao.getInstancia().guardar(areaEntity);	
		
	}
}
